package com.forum.module.blog.dal.mysql.article;

import com.forum.framework.common.pojo.PageResult;
import com.forum.framework.mybatis.core.mapper.BaseMapperX;
import com.forum.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.forum.module.blog.controller.article.vo.ArticlePageReqVO;
import com.forum.module.blog.dal.dataobject.article.ArticleDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ArticleMapper extends BaseMapperX<ArticleDO> {
    default PageResult<ArticleDO> selectPage(ArticlePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ArticleDO>()
                .eqIfPresent(ArticleDO::getTitle, reqVO.getTitle())
                .eqIfPresent(ArticleDO::getSummary, reqVO.getSummary())
                .likeIfPresent(ArticleDO::getContent, reqVO.getContent())
                .eqIfPresent(ArticleDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ArticleDO::getUserId, reqVO.getUserId()));
    }

    @Update("UPDATE forum_robot.blog_article SET likes = likes + 1 WHERE id = #{id}")
    void incrementLikes(@Param("id") Long id);
}
